package com.z6school.manage.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.z6school.manage.common.annotation.RequiredLog;
import com.z6school.manage.common.pojo.PageObject;
import com.z6school.manage.mapper.CurriculumMapper;
import com.z6school.manage.po.Curriculum;
import com.z6school.manage.po.Teacher;
import com.z6school.manage.service.CurriculumService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CurriculumServiceImpl implements CurriculumService {
    @Autowired
    private CurriculumMapper curriculumMapper;
    @Override
    @RequiredLog(operation = "查询课程信息")
    @RequiresPermissions("sys:curr:view")
    public PageObject<Curriculum> doFindAllMessage(String username, Integer pageCurrent) {
        //1.参数校验
        if(pageCurrent == null || pageCurrent<1)
            throw new IllegalArgumentException("页码值不正确");
        //2.PageHelper
        Page<Object> page = PageHelper.startPage(pageCurrent, 5);
        List<Curriculum> curriculumList = curriculumMapper.selectList(null);
        //3.封装结果
        return new PageObject<Curriculum>( page.getTotal(), curriculumList, Long.valueOf(page.getPages()), 5, pageCurrent);
    }

    @Override
    @RequiredLog(operation = "新增课程信息")
    @RequiresPermissions("sys:curr:edit")
    public void addCurriculumMessage(Curriculum curriculum) {
        curriculumMapper.insert(curriculum);
    }

    @Override
    @RequiredLog(operation = "删除课程信息")
    public void doDeleteObjects(String ids) {
        String[] split = ids.split(",");
        List<String> arrayList = new ArrayList<String>();
        for (int i=0;i<split.length;i++){
            arrayList.add(split[i]);
        }
        curriculumMapper.deleteBatchIds(arrayList);
    }
}
